<?php

namespace fastflow\driver\think;

use think\Db;
use fastflow\driver\interfaces\flowTemplate;

class flow implements flowTemplate
{
    
    public static function getFlow($param)
    {
        if (isset($param)) {
            $flow = Db::table('__FASTFLOW_FLOW__')->where($param)->select();
            foreach ($flow as &$item) {
                $item['graph'] = json_decode($item['graph'], true);
            }
            return $flow;
        }
        return false;
    }

    
    public static function saveGraph($param)
    {
        $flowid = $param['flowid'];
        $graph = $param['graph'];
        $image = $param['image'];
        $rowCount = Db::table('__FASTFLOW_FLOW__')->update(['id' => $flowid, 'graph' => json_encode($graph, JSON_NUMERIC_CHECK),'image'=>$image]);
        if ($rowCount == 1) {
            return ['code' => 1, 'msg' => '保存成功', 'data' => ''];
        }
        else {
            return ['code' => 0, 'msg' => '未更新任何数据', 'data' => ''];
        }
    }
}